#include "friendorgroupitem.h"
#include "ui_friendorgroupitem.h"
#include <QDebug>
#include "Core/tcpclient.h"
FriendOrGroupItem::FriendOrGroupItem(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FriendOrGroupItem)
{
    ui->setupUi(this);
    InitForUi();
    LinkTcpSignalAndSlot();

}

FriendOrGroupItem::~FriendOrGroupItem()
{
    delete ui;
}

void FriendOrGroupItem::InitForUi()
{
    this->setFixedHeight(100);
}

void FriendOrGroupItem::LinkTcpSignalAndSlot()
{
    connect(this,&FriendOrGroupItem::Sig_AddFriendRespond,
            TcpClient::get_instance(),&TcpClient::SendMsg);
}

void FriendOrGroupItem::setNotificationInfo(const QString &avatar, const QString &name, const QString &message, const QString &time, int type)
{
    if(avatar.size()==0){

    }
    m_name=name;
    ui->UserName->setText(name);
    ui->Infolabel->setText(message);
    qDebug()<<time;
    if(type==MSG_TYPE_FRIEND_INFORM_PULL_REQUEST){
        this->Type=type;
    }else if(type==MSG_TYPE_GROUP_INFORM_PULL_REQUEST){
        this->Type=type;
    }

}

void FriendOrGroupItem::on_AgreeBtn_clicked()
{
    if(Type==MSG_TYPE_FRIEND_INFORM_PULL_REQUEST){
        QJsonObject Info;
        Info["TAG"]=TcpClient::get_instance()->getUserName();
        Info["FROM"]=m_name;
        Info["STATUS"]=FRIEND_REQUEST_STATUS_AGREE;
        Info["SAY"]="OJBK";
        emit Sig_AddFriendRespond(MSG_TYPE_ADD_FRIEND_RESPOND,Info);
    }
}

void FriendOrGroupItem::on_RefuseBtn_clicked()
{
    if(Type==MSG_TYPE_FRIEND_INFORM_PULL_REQUEST){
        QJsonObject Info;
        Info["TAG"]=TcpClient::get_instance()->getUserName();
        Info["FROM"]=m_name;
        Info["STATUS"]=FRIEND_REQUEST_STATUS_RUFUSE;
        Info["SAY"]="GUN!!!!";
        emit Sig_AddFriendRespond(MSG_TYPE_ADD_FRIEND_RESPOND,Info);
    }
}
